package com.atguigu.juc.study.chapter09.atomics;

import java.util.concurrent.CountDownLatch;

/**
 * @author : leimingchao
 * @date Date : 2022年06月15日 22:41
 */
public class AtomicIntegerFieldUpdateDemo {

    public static void main(String[] args) {

        BankAccount bankAccount = new BankAccount();

        CountDownLatch countDownLatch = new CountDownLatch(10);

        for (int i = 1; i <= 10; i++) {

            new Thread(() -> {

                try {
                    for (int j = 1; j <= 1000; j++) {
                       // bankAccount.add();
                        bankAccount.transMoney(bankAccount);
                    }
                } finally {
                    countDownLatch.countDown();
                }

            }, String.valueOf(i)).start();

        }
        try {
            countDownLatch.await();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println(Thread.currentThread().getName() + "\t result:" + bankAccount.getMoney());
    }
}
